package org.road0329.dlt698.asn1.axdr;

import org.road0329.dlt698.ReverseByteArrayInputStream;
import org.road0329.dlt698.ReverseByteArrayOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AxdrType {
    private static Logger logger = LoggerFactory.getLogger(AxdrType.class);

    public void logEncodeMsg(String prefix, ReverseByteArrayOutputStream output) {

        if (logger.isDebugEnabled()) {
            byte[] buf = output.getArray();
            if (buf == null || buf.length == 0) {
                return;
            }
            int len = buf.length;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < len; i++) {
                sb.append(String.format("%02X ", buf[i]));
            }
            if (prefix == null || prefix.isEmpty()) {
                logger.debug(sb.toString());
            } else {
                logger.debug(prefix + " -> " + sb.toString());
            }

        }
    }

    public void logErrMsg(String message) {
        if (logger.isInfoEnabled()) {
            logger.info(message);

        }
    }

    public abstract int encode(ReverseByteArrayOutputStream output) throws Exception;

    public abstract int decode(ReverseByteArrayInputStream input) throws Exception;
}
